/**
 * TB_DOOR_SWIPERECORD
 * 
 *
 *<pre> 
 * 开发公司：苏州东大金点信息技术有限公司
 * 开发人员：唐红锋
 * 邮箱地址：55872655@qq.com
 * 创建时间：2019-09-30 18:57:54
 *</pre>
 */
$(function() {
	swipeRecord  = new SwipeRecord();
	swipeRecord.init();
	
	formUrl = swipeRecord.formUrl;
});

(function() {
	//定义常量
	var 	_consts = {
			GRID : "#swipeRecordGrid",// 列表对象
			PAGER : "#swipeRecordPager",// 列表分页
			FORM : '#swipeRecordForm',// 表单form
			FORMGET : '#swipeRecordFormGet'// 表单form
			
	};
	/**
	 * TB_DOOR_SWIPERECORD 对象
	 * @returns {SwipeRecord}
	 */
	SwipeRecord = function() {
		//定义属性
	};

	
	var dtFormatter = function (cellValue, options, rowObject) {
		   if(cellValue==null||cellValue==""){
			   return "";
		   }
		 //  alert("转义前"+cellValue);
		   //var date = new Date(cellValue);
		  // var date=new Date('2000-00-00 00:00:00');
		   //分割字符串处理
		   var arr=cellValue.split(" ")[0].split("-");
		   
		  var  y=arr[0];
		  var  m=arr[1];
		  var  d=arr[2];
		    
		   var  arrb=cellValue.split(" ")[1].split(":");
		   var   h=arrb[0];
		   var  f=arrb[1];
		   var  s=arrb[2];
		    
		   //date= new Date().format('2000-00-00 00:00:00');   
		   //var date=new Date('2000-01-00 00:00:00');
		   
		   
		  　/*alert("转义后日期"+date);
		       y = date.getFullYear();
		   　　m = date.getMonth() + 1;
		  　     d = date.getDate();
		   h = date.getHours() ;
		   f  = date.getMinutes();
		   s  = date. getSeconds();*/
		    
		 /*  if(m<10){
			   m= '0'+m;
		   }
		   if(d<10){
			   d= '0'+d;
		   }
		   if(h<10){
			   h= '0'+h;
		   }
		   if(f<10){
			   f= '0'+f;
		   }
		   if(s<10){
			   s= '0'+s;
		   }*/
		   　　return y+"-"+m+"-"+d+" "+h+":"+f+":"+s;

}
	
	/**
	 * 方法
	 */
	SwipeRecord.prototype = {
		consts:	_consts,
		/**
		 * 初始化
		 */
		init : function() {
			if (this.hasInit) // 是否已初始化
				return false;
			this.hasInit = true;
			if ($(this.consts.GRID).length > 0){//列表
				this._initGridList();
				
			}
			if ($(this.consts.FORM).length > 0){//表单
				this._initForm();
				this._initData();
				this._initOffice('e');
			}
			if ($(this.consts.FORMGET).length > 0){// 明细页面office控件初始化
				this._initOffice('r');
			}
		},
		_initOffice : function(_rights){
		},

		/**
		 * 初始列表
		 */
		_initGridList : function() {
			var me = this;
			$(this.consts.GRID).GridList(
					{
						url :  __ctx+'/rdp/logs/swipeRecord/listJson.htm',
						pager :this.consts.PAGER,
						colNames: ['RECID','时间','卡号','学工号','姓名','控制器号','控制器名称','门号','门名称','进出','有效','描述'],
				        colModel: [{
				                 	   name:'recid',
				                	   index: 'RECID'

										
				                	 	,hidden:true,key:true
				                	 	}, {
				                 	   name:'readdate',
				                	   index: 'READDATE',formatter: dtFormatter

										
				                	 					                	 	}, {
				                 	   name:'cardno',
				                	   index: 'CARDNO'

										
				                	 					                	 	},{
				                	   name:'usernum',
				                	   index: 'USERNUM'

				                	 						                   }, {
				                        name:'username',
				                	 	index: 'USERNAME'

				                	 												
				                	 						                     },{
				                	 	name:'controllersn',
				                	 	index: 'CONTROLLERSN'

				                	 												
				                	 						                    }, {
				                	 	name:'controllerno',
				                	 	index: 'CONTROLLERNO'

				                	 						                    },   {
				                 	   name:'doorindex',
				                	   index: 'DOORINDEX'

										
				                	 					                	 	}, {
				                	 	 name:'doorname',
				                	 	index: 'DOORNAME'
				                	 			
				                	 						                	}, {
				                	 	 name:'inout',
				                	 	 index: 'INOUT'

				                	 												
				                	                                            }, {
				                 	   name:'doorenable',
				                	   index: 'DOORENABLE'

										
				                	 					                	 	},  {
				                 	   name:'notes',
				                	   index: 'NOTES'

										
																          }
													 ]
	
					});
		},
		
		/**
		 * 初始化表单
		 */
		_initForm : function() {
			var me = this, form = $(this.consts.FORM), frm = form.form();
			me.formUrl = new com.lc.form.FormData(form);
			// 触发表单验证
			frm.valid();
			// 处理表单保存
			$(document).on('click', 'a.fa-save', function() {
				var $el = $(this);
				$el.button('loading');
				// office提交
        		OfficePlugin.submit();
				me.formUrl.submit(me._showResponse, $el);
			});
		},
		/**
		 * 初始化数据
		 */
		_initData : function(){
			if(!$.isEmpty(frameElement) 
				&& !$.isEmpty(frameElement.dialog) 
				&& !$.isEmpty(frameElement.dialog.params)
				&& !$.isEmpty(frameElement.dialog.params.data)){
				var data = frameElement.dialog.params.data;
				this.formUrl.setData("[name^='m:']", data);
				AttachementControl.initDataTo($("div[name='div_attachment_container']")); //附件初始化
			}else{
				$("[name^='m:']", $(_consts.FORM)).each(function(){
					var data = $(this);
	        		// 单选框特殊处理 
	            	if(data.is('input') && "radio" == data.attr("type")){
			        		var defaultVal = data.attr("defaultVal");
			        		var defaultValue = data.attr("defaultValue");
		            		if(defaultValue=="true"&&defaultVal=="true"){
		            			data.prop("checked", "checked");
		            		}
		        	}
		        });
			}
			
			this.formUrl.validate();
		},
		/**
		 * 表单成功返回信息
		 * 
		 * @param responseText
		 */
		_showResponse : function(responseText) {
			var msg = new com.lc.form.ResultMessage(responseText);
			if (msg.isSuccess()) {
				DialogUtil.confirm(msg.getMessage() + ',是否继续操作',
					function(rtn) {
					if(rtn)
						window.location.reload(true);
					else
						window.location.href = __ctx+'/rdp/logs/swipeRecord/list.htm';
					});
			} else {
				DialogUtil.error(msg.getMessage());
			}
		}
	};
})();